package top.jidanmian.iot.server.mqtt;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.GetMapping;



@RestController
public class MqttController {
    private MqttConfiguration mqttConfiguration;
    public MqttController(MqttConfiguration mqttConfiguration)
    {
        this.mqttConfiguration = mqttConfiguration;
    }

    @PostMapping("/mqtt/pub")
    public String publish(@RequestBody MqttRequestBody body) {
        mqttConfiguration.publish(body.topic(), body.message());
        
        return "Publish - Topic: " + body.topic() + ", message: " + body.message();
    }

    @GetMapping("/mqtt/pub")
    public String testpublish() {
        return new String("pub");
    }
    
    
}
